<#include "/pages/macro.ftl">
<@override name="resources">
<script src="${base}/scripts/umeditor/template.min.js"></script>
<script src="${base}/scripts/umeditor/umeditor.config.js"></script>
<script src="${base}/scripts/umeditor/umeditor.min.js"></script>
<script src="${base}/scripts/jquery.serialize-object.min.js"></script>

<link rel="stylesheet" href="${base}/scripts/umeditor/themes/default/css/umeditor.min.css">
    <#assign menuIdx = 3>
</@override>
<@override name="title">发表日志</@override>
<@override name="main-content">
    <@logon>
    <div class="ui centered twelve wide column" style="margin-top: 50px;" id="post-add-container">
        <div class="ui sticky">
            <form class="ui fluid form" id="post-form">
                <div class="ui error message"></div>
                <div class="fields">
                    <div class="four wide field">
                        <label for="category_id">分类</label>
                        <div class="ui selection dropdown">
                            <input type="hidden" name="category_id">
                            <input type="hidden" name="user_id" value="${session.user.id}">

                            <div class="default text">请选择日志分类</div>
                            <i class="dropdown icon"></i>
                            <div class="menu">
                                <#if categories??>
                                    <#list categories as category>
                                        <div class="item" data-value="${category.id}">${category.name}</div>
                                    </#list>
                                </#if>
                            </div>

                        </div>
                    </div>
                    <div class="twelve wide field">
                        <label for="title">标题</label>
                        <div class="ui input">
                            <input type="text" name="title" id="title" placeholder="请输入标题" autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="field">
                    <label for="content">标题</label>

                    <textarea name="content" id="content" cols="30" rows="10" style="width: 100%;"></textarea>

                </div>

            </form>
            <div class="ui center aligned basic segment">
                <a class="ui submit blue icon button"><i class="save icon"></i>保存
                </a>
                <a class="ui reset button">Reset</a>
            </div>
        </div>
    </div>
    </@logon>
</@override>
<@override name="script">
<script>
    $(document).ready(function () {
        var editor = UM.getEditor("content");


        $("#post-form").form({
            on: "submit",
            fields: {
                title: {
                    identifier: "title",
                    rules: [
                        {
                            type: "empty",
                            prompt: "标题不能为空"
                        }
                    ]
                }, content: {
                    identifier: "content",
                    rules: [
                        {
                            type: "empty",
                            prompt: "内容不能为空"
                        }
                    ]
                }, category_id: {
                    identifier: "category_id",
                    rules: [
                        {
                            type: "empty",
                            prompt: "分类不能为空"
                        }
                    ]
                }
            }

        }).api({

            url: "${base}/post/save",
            method: "POST",
            serializeForm: true,
            successTest: function (response) {
                return response.success || false;

            }, onSuccess: function (response) {
                $("#post-form").form("reset");
                editor.setContent("");
            }

        });
        $(".submit.button").click(function () {
            $("#post-form").form("submit");

        });

        $(".reset.button").click(function () {
            $("#post-form").form("reset");
            editor.setContent("");

        });

    });
</script>
</@override>
<@extends name="admin-layout.ftl"></@extends>